<?php

/**
 * Description of AbstractController2
 *
 * @author JoasRamos
 */
abstract class AbstractController {

    public static $CREATE = '1',
            $RETRIEVE = '2',
            $UPDATE = '3',
            $DELETE = '4';

    public function __construct($action) {
        $this->defaultAction($action);
    }

    function defaultAction($action) {
        switch ($action) {
            case md5(self::$CREATE):
                $this->create();
                break;
            case md5(self::$RETRIEVE):
                $this->retrieve();
                break;
            case md5(self::$UPDATE):
                $this->update();
                break;
            case md5(self::$DELETE):
                $this->delete();
                break;
            default :
                $this->personalizeAction($action);
        }
    }

    function checkRoles($nivel) {
        session_start();
        if ($nivel != $_SESSION['current_user']['nivel']) {
            return false;
        }
        return true;
    }

    function initDefaultSession() {
        session_start();
        $usuario_padrao = array("id" => "000", "nome" => "Visitante", "nivel" => "0", "desc_nivel" => "Padrão");
        $_SESSION["current_user"] = $usuario_padrao;
    }

    function destroySession() {
        session_start();
        if (session_destroy())
            return true;
        return false;
    }

    abstract function create();

    abstract function retrieve($id);

    abstract function delete();

    abstract function personalizeAction($action);
}

?>
